package thread;

class MyThread3 implements Runnable {
    public void run() {
        while (true) {
            System.out.println("hello Runnable");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class ThreaDemo3 {
    public static void main(String[] args) {
        Runnable runnable = new MyThread3();
        Thread t = new Thread(runnable);
        //Runnable本身是一个可以执行的逻辑；只是一段可以执行的代码
        //还是要搭配Thread类型，才能真正在系统中创建出线程，这样写是把 线程和 要执行的任务解耦合
        //也可以写成 Thread t = new Thread(new MyThread3());
        t.start();
        while (true) {
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
